home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 7 / FM Towns Free Software Collection 7.iso / ms_dos / dmove86 / dmove86.c < prev    next >
Text File  |  1993-11-30  |  4KB  |  232 lines

  1. /*
  2.  
  3. dmove86.c version 1.20a
  4. Copyright (c) 1993 Delmonta
  5.  
  6. */
  7.  
  8. #include<stdio.h>
  9. #include<malloc.h>
  10. #include<dos.h>
  11. #include<ctype.h>
  12. #include<process.h>
  13. #include"dmove86.h"
  14.  
  15. int        Drive;
  16. unsigned int    Fatsize;
  17. struct DPB    Dpb;
  18. unsigned int    *Fat;
  19.  
  20. recursive
  21. int        control(parent)
  22. struct DIRENTRY far *parent;
  23. {
  24.     struct DIRENTRY far **dirtbl;
  25.  
  26.     unsigned int    secnum;    /* そのディレクトリが占めるセクタ数    */
  27.     unsigned int    dirnum;    /* ディレクトリエントリの数        */
  28.  
  29. register unsigned int    i,n;    /* ループカウンターなどの一時変数    */
  30.  
  31.     struct SECTBL    sectop;
  32.     struct SECTBL    *sectbl;
  33.  
  34. REREAD:;
  35.     secnum = 0;
  36.     sectbl = §op;
  37.  
  38.     if    (parent == NULL)    /* ルートディレクトリの場合    */
  39.     {
  40.         for    (i=Dpb.iplsectors+Fatsize*Dpb.fatnum ;
  41.                 i<Dpb.data_sec ; i++)
  42.         {
  43.             struct SECTBL    *up;
  44.  
  45.             sectbl->next = (struct SECTBL *)malloc
  46.                         (sizeof(struct SECTBL));
  47.  
  48.             if    (sectbl->next == NULL)
  49.                 goto ENDROOTDIR;
  50.  
  51.             up = sectbl;
  52.             sectbl = up->next;
  53.  
  54.             sectbl->buf = (struct DIRENTRY far *)
  55.                     farmalloc(Dpb.seclen);
  56.             if    (sectbl->buf == NULL)
  57.             {
  58.                 free(sectbl);
  59.                 up->next = NULL;
  60.                 goto ENDROOTDIR;
  61.             }
  62.  
  63.             if    ((n=rdabssec(sectbl->buf,i,Drive)) & 0x100)
  64.             {
  65.                 dm_errmes("セクタの読み込みに失敗しました");
  66.                 farfree(sectbl->buf);
  67.                 free(sectbl);
  68.                 up->next = NULL;
  69.                 goto ENDROOTDIR;
  70.             }
  71.  
  72.             sectbl->num = i;
  73.             secnum++;
  74.             sectbl->next = NULL;
  75.         }
  76.  
  77. ENDROOTDIR:;
  78.     }
  79.     else                /* サブディレクトリの場合    */
  80.     {    unsigned int    cluster = parent->cluster;
  81.         unsigned int    sector;
  82.  
  83.         do
  84.         {
  85.             sector = CL2SEC(cluster);
  86.  
  87.             for    (i=0 ; i<=Dpb.sec_clu ; i++)
  88.             {
  89.  
  90.                 struct SECTBL    *up = sectbl;
  91.  
  92.                 up->next = (struct SECTBL *)malloc
  93.                         (sizeof(struct SECTBL));
  94.  
  95.                 sectbl = up->next;
  96.  
  97.                 if    (sectbl == NULL)
  98.                 {
  99.                     goto ENDSUBDIR;
  100.                 }
  101.                 sectbl->buf = (struct DIRENTRY far *)
  102.                         farmalloc(Dpb.seclen);
  103.  
  104.                 if    (sectbl->buf == NULL)
  105.                 {
  106.                     free(sectbl);
  107.                     up->next = NULL;
  108.                     goto ENDSUBDIR;
  109.                 }
  110.  
  111.                 if    ((n=rdabssec(sectbl->buf,
  112.                         sector+i,Drive)) & 0x100)
  113.                 {
  114.                     dm_errmes("セクタの読み込みに失敗しました");
  115.                     farfree(sectbl->buf);
  116.                     free(sectbl);
  117.                     up->next = NULL;
  118.                     goto ENDSUBDIR;
  119.                 }
  120.  
  121.                 sectbl->num = sector+i;
  122.                 sectbl->next = NULL;
  123.                 secnum++;
  124.             }
  125.             cluster = Fat[cluster];
  126.         } while    (cluster!=0xffff);
  127. ENDSUBDIR:;
  128.     }
  129.  
  130.     /* 以降、ルート/サブ共通の処理 */
  131.  
  132.     if    (secnum == 0)
  133.     {
  134.         dm_errmes("ディレクトリが全く読み込まれませんでした。");
  135.         return 5;
  136.     }
  137.  
  138.     sectbl = sectop.next;        /* 実はsectopはダミーなのです */
  139.  
  140.     dirtbl = (struct DIRENTRY far **)malloc(sizeof(struct DIRENTRY far *)
  141.         * secnum * DIRSEC);
  142.  
  143.     if    (dirtbl == NULL)
  144.     {
  145.         freesectbl(sectop.next);
  146.         dm_errmes("メモリ不足です。");
  147.         return 4;
  148.     }
  149.  
  150.     dirnum = n = 0;
  151.  
  152.     while(sectbl != NULL)
  153.     {
  154.         for    (i=0 ; i<DIRSEC ; i++)
  155.         {
  156.             dirtbl[n] = sectbl->buf + i;
  157.  
  158.             if    (dirtbl[n]->filename[0]=='\0' && dirnum==0)
  159.                 dirnum = n;
  160.  
  161.             n++;
  162.         }
  163.  
  164.         sectbl = sectbl->next;
  165.     }
  166.  
  167.     if    (dirnum == 0)
  168.         dirnum = secnum*DIRSEC;
  169.  
  170.     i = 0;
  171. REMENU:;
  172.  
  173.     i = dmmenu(dirtbl, dirnum, i/4, parent!=NULL);
  174.  
  175.     switch (i & 3)
  176.     {
  177.         case UPDIR:
  178.             free(dirtbl);
  179.             freesectbl(sectop.next);
  180.             return 0;
  181.  
  182.         case CHGDIR:
  183.             control(dirtbl[i/4]);
  184.             break;
  185.  
  186.         case WRTDIR:
  187.             writedir(sectop.next,dirtbl,dirnum);
  188.             break;
  189.  
  190.         case ORIGIN:
  191.             free(dirtbl);
  192.             freesectbl(sectop.next);
  193.             goto REREAD;
  194.  
  195.     }
  196.     goto REMENU;
  197. }
  198.  
  199. int    main(argc,argv)
  200. int    argc;
  201. char    *argv[];
  202. {
  203.     if    (argc != 2)
  204.     {    printf("書式 : dmove86 <ドライブ名>\n");
  205.         exit(1);
  206.     }
  207.  
  208.     Drive = toupper(argv[1][0]) - 'A';
  209.  
  210.     if    (Drive<0 || Drive>25)
  211.     {    printf("不正なドライブ名です.\n");
  212.         exit(2);
  213.     }
  214.  
  215.     if    (getdpb() == -1)
  216.     {    printf("指定されたドライブは存在しません.\n");
  217.         exit(2);
  218.     }
  219.  
  220.     Fat = getfat();
  221.  
  222.     if    (Fat == NULL)
  223.     {    printf("FATの読み込みに失敗しました.\n");
  224.         exit(3);
  225.     }
  226.  
  227.     mkscreen();
  228.  
  229.     return (control(NULL));
  230. }
  231.  
  232.